<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ShopEase - 简单便捷的购物体验</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
    <script>
        tailwind.config = {
            theme: {
                extend: {
                    colors: {
                        primary: '#165DFF',
                        secondary: '#FF7D00',
                        neutral: {
                            100: '#F5F7FA',
                            200: '#E5E6EB',
                            300: '#C9CDD4',
                            400: '#86909C',
                            500: '#4E5969',
                            600: '#272E3B',
                            700: '#1D2129',
                        }
                    },
                    fontFamily: {
                        inter: ['Inter', 'system-ui', 'sans-serif'],
                    },
                }
            }
        }
    </script>
    <style type="text/tailwindcss">
        @layer utilities {
            .content-auto {
                content-visibility: auto;
            }
            .card-shadow {
                box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
            }
            .card-hover {
                transition: transform 0.3s ease, box-shadow 0.3s ease;
            }
            .card-hover:hover {
                transform: translateY(-5px);
                box-shadow: 0 10px 30px rgba(22, 93, 255, 0.15);
            }
        }
    </style>
</head>
<body class="font-inter bg-neutral-100 text-neutral-700">
    <!-- 导航栏 -->
    <nav class="sticky top-0 z-50 bg-white shadow-md transition-all duration-300">
        <div class="container mx-auto px-4">
            <div class="flex items-center justify-between h-16 md:h-20">
                <!-- Logo -->
                <a href="/" class="flex items-center space-x-2">
                    <span class="text-primary text-2xl font-bold">ShopEase</span>
                </a>
                
                <!-- 搜索框 -->
                <div class="hidden md:flex flex-1 max-w-xl mx-8 relative">
                    <form action="/search" method="GET">
                        <input 
                            type="text" 
                            id="search-input"
                            name="query"
                            placeholder="搜索商品..." 
                            class="w-full pl-4 pr-10 py-2 rounded-full border border-neutral-200 focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-all"
                        >
                        <button type="submit" class="absolute right-2 top-1/2 transform -translate-y-1/2 text-neutral-400 hover:text-primary transition-colors">
                            <i class="fa fa-search"></i>
                        </button>
                    </form>
                    <div id="search-suggestions" class="absolute top-full left-0 right-0 hidden"></div>
                </div>
                
                <!-- 导航链接 -->
                <div class="flex items-center space-x-4 md:space-x-6">
                    <a href="/search" class="text-neutral-500 hover:text-primary transition-colors hidden md:block">
                        <i class="fa fa-search text-lg"></i>
                    </a>
                    <a href="#" class="text-neutral-500 hover:text-primary transition-colors relative">
                        <i class="fa fa-shopping-cart text-lg"></i>
                        <span class="absolute -top-2 -right-2 bg-secondary text-white text-xs rounded-full h-5 w-5 flex items-center justify-center">3</span>
                    </a>
                    <a href="#" class="text-neutral-500 hover:text-primary transition-colors">
                        <i class="fa fa-heart-o text-lg"></i>
                    </a>
                    <a href="#" class="text-neutral-500 hover:text-primary transition-colors">
                        <i class="fa fa-user-o text-lg"></i>
                    </a>
                </div>
            </div>
            
            <!-- 移动端搜索框 -->
            <div class="md:hidden pb-4 relative">
                <form action="/search" method="GET">
                    <input 
                        type="text" 
                        id="search-input-mobile"
                        name="query"
                        placeholder="搜索商品..." 
                        class="w-full pl-4 pr-10 py-2 rounded-full border border-neutral-200 focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-all"
                    >
                    <button type="submit" class="absolute right-2 top-1/2 transform -translate-y-1/2 text-neutral-400 hover:text-primary transition-colors">
                        <i class="fa fa-search"></i>
                    </button>
                </form>
                <div id="search-suggestions-mobile" class="absolute top-full left-0 right-0 hidden"></div>
            </div>
        </div>
    </nav>

    <!-- 主内容 -->
    <main class="container mx-auto px-4 py-8">
        {% block content %}
        {% endblock %}
    </main>

    <!-- 页脚 -->
    <footer class="bg-neutral-700 text-white py-12 mt-16">
        <div class="container mx-auto px-4">
            <div class="grid grid-cols-1 md:grid-cols-4 gap-8">
                <div>
                    <h3 class="text-xl font-bold mb-4">ShopEase</h3>
                    <p class="text-neutral-300 mb-4">简单便捷的购物体验，尽在ShopEase。</p>
                    <div class="flex space-x-4">
                        <a href="#" class="text-neutral-300 hover:text-white transition-colors">
                            <i class="fa fa-facebook"></i>
                        </a>
                        <a href="#" class="text-neutral-300 hover:text-white transition-colors">
                            <i class="fa fa-twitter"></i>
                        </a>
                        <a href="#" class="text-neutral-300 hover:text-white transition-colors">
                            <i class="fa fa-instagram"></i>
                        </a>
                        <a href="#" class="text-neutral-300 hover:text-white transition-colors">
                            <i class="fa fa-linkedin"></i>
                        </a>
                    </div>
                </div>
                
                <div>
                    <h4 class="font-medium text-lg mb-4">快速链接</h4>
                    <ul class="space-y-2">
                        <li><a href="#" class="text-neutral-300 hover:text-white transition-colors">首页</a></li>
                        <li><a href="#" class="text-neutral-300 hover:text-white transition-colors">商品分类</a></li>
                        <li><a href="#" class="text-neutral-300 hover:text-white transition-colors">新品上市</a></li>
                        <li><a href="#" class="text-neutral-300 hover:text-white transition-colors">热销商品</a></li>
                        <li><a href="#" class="text-neutral-300 hover:text-white transition-colors">关于我们</a></li>
                    </ul>
                </div>
                
                <div>
                    <h4 class="font-medium text-lg mb-4">客户服务</h4>
                    <ul class="space-y-2">
                        <li><a href="#" class="text-neutral-300 hover:text-white transition-colors">联系我们</a></li>
                        <li><a href="#" class="text-neutral-300 hover:text-white transition-colors">常见问题</a></li>
                        <li><a href="#" class="text-neutral-300 hover:text-white transition-colors">配送政策</a></li>
                        <li><a href="#" class="text-neutral-300 hover:text-white transition-colors">退换货政策</a></li>
                        <li><a href="#" class="text-neutral-300 hover:text-white transition-colors">隐私政策</a></li>
                    </ul>
                </div>
                
                <div>
                    <h4 class="font-medium text-lg mb-4">订阅我们</h4>
                    <p class="text-neutral-300 mb-4">订阅我们的新闻通讯，获取最新优惠和产品信息。</p>
                    <form class="flex">
                        <input type="email" placeholder="输入您的邮箱" class="flex-1 px-4 py-2 rounded-l-md text-neutral-700 focus:outline-none">
                        <button type="submit" class="bg-primary hover:bg-primary/90 transition-colors px-4 py-2 rounded-r-md">
                            订阅
                        </button>
                    </form>
                </div>
            </div>
            
            <div class="border-t border-neutral-600 mt-8 pt-8 text-center text-neutral-400">
                <p>&copy; 2025 ShopEase. 保留所有权利。</p>
            </div>
        </div>
    </footer>

    <script src="{{ url_for('static', filename='js/search.js') }}"></script>
    <script>
        // 导航栏滚动效果
        window.addEventListener('scroll', function() {
            const nav = document.querySelector('nav');
            if (window.scrollY > 10) {
                nav.classList.add('shadow-lg');
                nav.classList.add('bg-white/95');
                nav.classList.add('backdrop-blur-sm');
            } else {
                nav.classList.remove('shadow-lg');
                nav.classList.remove('bg-white/95');
                nav.classList.remove('backdrop-blur-sm');
            }
        });
        
        // 移动端搜索框也使用相同的搜索建议逻辑
        document.addEventListener('DOMContentLoaded', function() {
            const mobileInput = document.getElementById('search-input-mobile');
            const mobileSuggestions = document.getElementById('search-suggestions-mobile');
            
            if (mobileInput && mobileSuggestions) {
                // 复制相同的事件监听器
                mobileInput.addEventListener('input', function(e) {
                    const query = e.target.value.trim();
                    if (query.length < 2) {
                        mobileSuggestions.style.display = 'none';
                        return;
                    }
                    
                    clearTimeout(timeoutId);
                    timeoutId = setTimeout(() => {
                        fetchSuggestions(query, mobileSuggestions);
                    }, 300);
                });
                
                mobileInput.addEventListener('focus', function() {
                    if (this.value.trim().length >= 2) {
                        fetchSuggestions(this.value.trim(), mobileSuggestions);
                    }
                });
                
                // 点击其他区域关闭建议框
                document.addEventListener('click', function(e) {
                    if (!mobileInput.contains(e.target) && !mobileSuggestions.contains(e.target)) {
                        mobileSuggestions.style.display = 'none';
                    }
                });
            }
            
            // 修改后的fetchSuggestions函数，接受容器参数
            function fetchSuggestions(query, container) {
                const userId = 1;
                
                fetch(`/api/suggestions?query=${encodeURIComponent(query)}&user_id=${userId}`)
                    .then(response => response.json())
                    .then(suggestions => {
                        if (suggestions.length > 0) {
                            displaySuggestions(suggestions, query, container);
                        } else {
                            container.style.display = 'none';
                        }
                    })
                    .catch(error => {
                        console.error('获取搜索建议失败:', error);
                        container.style.display = 'none';
                    });
            }
            
            // 修改后的displaySuggestions函数，接受容器参数
            function displaySuggestions(suggestions, query, container) {
                container.innerHTML = '';
                
                const ul = document.createElement('ul');
                ul.className = 'absolute z-50 w-full bg-white rounded-lg shadow-lg mt-1 overflow-hidden';
                
                suggestions.forEach(suggestion => {
                    const li = document.createElement('li');
                    let iconClass = 'fa-search';
                    if (suggestion.type === 'history') {
                        iconClass = 'fa-history';
                    } else if (suggestion.type === 'product') {
                        iconClass = 'fa-shopping-bag';
                    } else if (suggestion.type === 'collaborative') {
                        iconClass = 'fa-users';
                    }
                    
                    const highlightedText = suggestion.value.replace(
                        new RegExp(query, 'gi'),
                        match => `<span class="text-primary font-medium">${match}</span>`
                    );
                    
                    li.className = 'px-4 py-2 hover:bg-neutral-100 cursor-pointer transition-colors flex items-center';
                    li.innerHTML = `
                        <i class="fa ${iconClass} text-neutral-400 mr-3"></i>
                        <span>${highlightedText}</span>
                    `;
                    
                    li.addEventListener('click', function() {
                        mobileInput.value = suggestion.value;
                        container.style.display = 'none';
                        
                        const form = mobileInput.closest('form');
                        if (form) {
                            form.submit();
                        }
                    });
                    
                    ul.appendChild(li);
                });
                
                container.appendChild(ul);
                container.style.display = 'block';
            }
        });
    </script>
</body>
</html>    